home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / lpq / lpq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-24  |  1.8 KB  |  89 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef lint
  8. char copyright[] =
  9. "@(#) Copyright (c) 1983 Regents of the University of California.\n\
  10.  All rights reserved.\n";
  11. #endif not lint
  12.  
  13. #ifndef lint
  14. static char sccsid[] = "@(#)lpq.c    5.3 (Berkeley) 4/30/87";
  15. #endif not lint
  16.  
  17. /*
  18.  * Spool Queue examination program
  19.  *
  20.  * lpq [-l] [-Pprinter] [user...] [job...]
  21.  *
  22.  * -l long output
  23.  * -P used to identify printer as per lpr/lprm
  24.  */
  25.  
  26. #include "lp.h"
  27.  
  28. char    *user[MAXUSERS];    /* users to process */
  29. int    users;            /* # of users in user array */
  30. int    requ[MAXREQUESTS];    /* job number of spool entries */
  31. int    requests;        /* # of spool requests */
  32. static void usage();
  33. int debug;
  34.  
  35. main(argc, argv)
  36.     register int    argc;
  37.     register char    **argv;
  38. {
  39.     extern char    *optarg;
  40.     extern int    optind;
  41.     int    ch, lflag;        /* long output option */
  42.  
  43.     name = *argv;
  44.     if (gethostname(host, sizeof(host))) {
  45.         perror("lpq: gethostname");
  46.         exit(1);
  47.     }
  48.     openlog("lpd", 0, LOG_LPR);
  49.  
  50.     lflag = 0;
  51.     while ((ch = getopt(argc, argv, "lP:")) != EOF)
  52.         switch((char)ch) {
  53.         case 'l':            /* long output */
  54.             ++lflag;
  55.             break;
  56.         case 'P':        /* printer name */
  57.             printer = optarg;
  58.             break;
  59.         case '?':
  60.         default:
  61.             usage();
  62.         }
  63.  
  64.     if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
  65.         printer = DEFLP;
  66.  
  67.     for (argc -= optind, argv += optind; argc; --argc, ++argv)
  68.         if (isdigit(argv[0][0])) {
  69.             if (requests >= MAXREQUESTS)
  70.                 fatal("too many requests");
  71.             requ[requests++] = atoi(*argv);
  72.         }
  73.         else {
  74.             if (users >= MAXUSERS)
  75.                 fatal("too many users");
  76.             user[users++] = *argv;
  77.         }
  78.  
  79.     displayq(lflag);
  80.     exit(0);
  81. }
  82.  
  83. static void
  84. usage()
  85. {
  86.     puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]");
  87.     exit(1);
  88. }
  89.